﻿//Write a program to convert decimal numbers to their hexadecimal representation.
//The sulution is the same as task 1, but with a little change in the formula - we divide the number with 16

using System;
using System.Collections.Generic;

class DecimalToHexadecimal
{
    static void Main(string[] args)
    {
        Console.WriteLine("Please, enter a number");
        int number = int.Parse(Console.ReadLine());

        List<char> hex = ToHexadecimal(number);

        Console.WriteLine("Hexadecimal representation: ");
        for (int i = 0; i < hex.Count; i++) //Print the list
        {
            Console.Write(hex[i]);
        }

        Console.WriteLine();

    }

    static List<char> ToHexadecimal(int number) //Hexadecimal representation method, using the algorithm for decimal to hexadecimal convertion
    {
        int reminder;
        int temp = number;
        List<char> result = new List<char>();

        do
        {
            reminder = temp % 16;
            temp = temp / 16;
            if (reminder >= 10)
            {
                switch (reminder)
                {
                    case 10: reminder = 'A'; break;
                    case 11: reminder = 'B'; break;
                    case 12: reminder = 'C'; break;
                    case 13: reminder = 'D'; break;
                    case 14: reminder = 'E'; break;
                    case 15: reminder = 'F'; break;
                }
            }
            result.Add((char)reminder);
        }
        while (temp > 0);

        result.Reverse();

        return result;
    }
}

